﻿using Jay.Sc2.Bof.Lib.State;

namespace Jay.Sc2.Bof.Lib.Action.Terran
{
	public class ActionProduceMissileTurret : ActionProduceFromSCV
	{
		public static ActionProduceMissileTurret Instance = new ActionProduceMissileTurret();

		private ActionProduceMissileTurret() : base(25, 100, 0) { }

		public override string EventName { get { return "ActionSpawnMissileTurret"; } }

		public override TerranState.TerranBuilding GetBuilding(TerranState state) { return state.MissileTurret; }

		public override bool IsInvalid(IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			return base.IsInvalid(bo) || (state.EngineeringBay.Total) == 0;
		}

		public override bool IsUseless(IBuildOrder bo, IGoal goal)
		{
			TerranState current = bo.State as TerranState;
			if (base.IsUseless(bo, goal)) return true;
			int total = 0;
			foreach (IState state in goal)
			{
				TerranState s = state as TerranState;
				total += s.MissileTurret.Count;
			}
			return total <= current.MissileTurret.Total;
		}

		public override bool HaveTechnology(IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			return state.EngineeringBay.Count > 0;
		}

		private IAction[,] m_Requirements;
		public override IAction[,] Requirements
		{
			get
			{
				if (m_Requirements == null)
					m_Requirements = new IAction[,] { { ActionProduceEngineeringBay.Instance } };
				return m_Requirements;
			}
		}
	}
}
